var net = require('net');
var netpkg = require('./netpkg');

var sock = net.connect({
    port:6080,
    host:"127.0.0.1",
},function(){
    console.log('========connected to server===========');
})

sock.on('connect',function(){
    console.log('connect success!');

    //测试一个整包
    // sock.write(netpkg.package_data("Hello!"));

    //测试两个整包合在一起发送的
    // sock.write(netpkg.test_pkg_two_action("start", "stop"));

    //测试一个包分成两部分发送的情况
    var buf_set = netpkg.test_pkg_two_slice("Bla", "ke");
    sock.write(buf_set[0]); // 
    setTimeout(function() {
        sock.write(buf_set[1]);
    }, 5000);
})

sock.on('data',function(data){
    console.log('=======data========',data);
    //data 是 Buffer

   
})

sock.on("end",function(){
    console.log('=====end========')
})

sock.on("close",function(){
    console.log('=====close========')
})

sock.on('error',function(err){
    console.log('========error========',err);
})